/*
package cn.com.bluemoon.daps.common.datascope.log.aspect;

import cn.com.bluemoon.daps.api.sys.RemoteSysOperateLogService;
import cn.com.bluemoon.daps.common.datascope.BmPermission;
import cn.com.bluemoon.daps.common.datascope.log.ILogService;
import cn.com.bluemoon.daps.common.datascope.log.OperateLog;
import cn.com.bluemoon.daps.common.datascope.log.constants.OperateLogConstant;
import cn.com.bluemoon.daps.common.datascope.log.enums.ModuleObject;
import cn.com.bluemoon.daps.common.datascope.log.enums.OperateType;
import cn.com.bluemoon.daps.common.datascope.log.holder.ProcessLogHolder;
import cn.com.bluemoon.daps.common.domain.UserInfoHolder;
import cn.com.bluemoon.daps.common.exception.DapException;
import cn.com.bluemoon.daps.common.exception.DapThrowException;
import cn.com.bluemoon.daps.domp.api.IDompService;
import cn.com.bluemoon.daps.system.entity.DapOperateLog;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.exception.ExceptionUtils;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Lazy;
import org.springframework.core.annotation.Order;
import org.springframework.util.ObjectUtils;

import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.function.Function;
import java.util.stream.Collectors;

*/
/**
 *
 **//*

@Configuration
@Aspect
@ConditionalOnProperty(
        value = {"bm.dap.http.log.enable"},
        matchIfMissing = true
)
@Order(Integer.MAX_VALUE - 3)
@Slf4j
public class OperateLogAspect {

    */
/**
     * 缓存自定义日志收集bean
     *//*

    private static final ConcurrentHashMap<Class<? extends ILogService>, ILogService> beforeMap = new ConcurrentHashMap<>();
    private final ConcurrentHashMap<Class<? extends ILogService>, ILogService> processMap = new ConcurrentHashMap<>();
    private final ConcurrentHashMap<Class<? extends ILogService>, ILogService> afterMap = new ConcurrentHashMap<>();

    @Resource
    @Lazy
    private RemoteSysOperateLogService remoteSysOperateLogService;

    @Resource
    @Lazy
    private IDompService iDompService;

    @Pointcut(value = "@annotation(cn.com.bluemoon.daps.common.datascope.BmPermission)")
    public void logPointCut() {
    }

    */
/**
     * 切面记录日志
     *//*

    @Around("logPointCut()&& @annotation(bmPermission)")
    public Object aroundAdvice(ProceedingJoinPoint joinPoint, BmPermission bmPermission) throws Throwable {
        Object proceed = null;
        boolean result = false;
        String errorMsg = "";
        OperateLog operateLog = bmPermission.log();
        String beforeLog = beforeMap.computeIfAbsent(operateLog.before(), getClassILogServiceFunction())
                .collector(operateLog, joinPoint, null, UserInfoHolder.getUserInfoOrEmpty());
        try {
            proceed = joinPoint.proceed();
            result = true;
        } catch (Throwable throwable) {
            errorMsg = ExceptionUtils.getMessage(throwable);
            throw throwable;
        } finally {
            String process = processMap.computeIfAbsent(operateLog.process(), getClassILogServiceFunction())
                    .collector(operateLog, joinPoint, proceed, UserInfoHolder.getUserInfoOrEmpty());
            String after = afterMap.computeIfAbsent(operateLog.after(), getClassILogServiceFunction())
                    .collector(operateLog, joinPoint, proceed, UserInfoHolder.getUserInfoOrEmpty());
            // 日志
            StringBuffer buffer = new StringBuffer();
            if(StringUtils.isNotBlank(beforeLog)){
                buffer.append(String.format("执行前：%s;", beforeLog));
            }
            if(StringUtils.isNotBlank(process)){
                buffer.append(String.format("\n执行中：%s;",process));
            }
            if(StringUtils.isNotBlank(after)){
                buffer.append(String.format("\n执行后：%s;", after));
            }
            List<String> menuList = Arrays.asList(bmPermission.value());
            saveOpLog(operateLog, result, errorMsg, buffer.toString(), menuList);
            ProcessLogHolder.clear();
        }
        return proceed;
    }

    private void saveOpLog(OperateLog operateLog, boolean result, String errorMsg, String logContent, List<String> menuList) {
        // 查询菜单
        try {
            Map<String, List<IDompService.MenuDto>> menuMap = iDompService.getMenuPathByTokenAndUserId(UserInfoHolder.getUserInfo().get().getToken(), UserInfoHolder.getAccount());
            List<IDompService.MenuDto> menuDtos = menuList.stream().map(m -> menuMap.get(m)).collect(ArrayList::new, ArrayList::addAll, ArrayList::addAll);
            String menuName = menuDtos.stream().filter(m -> menuList.contains(m.getMenu_path())).map(IDompService.MenuDto::getMenu_name).collect(Collectors.joining(","));
            DapOperateLog opLog = new DapOperateLog();
            opLog.setErrorMessage(errorMsg);
            OperateType type = operateLog.type();
            opLog.setOpType(ObjectUtils.isEmpty(type) ? OperateType.UNKNOWN.getType() : type.getType());
            ModuleObject moduleObject = operateLog.moduleName();
            opLog.setModuleName(ObjectUtils.isEmpty(moduleObject) ? ModuleObject.UNKNOWN.getModule() : moduleObject.getModule());
            opLog.setMenuName(menuName);
            opLog.setOpDetail(logContent);
            opLog.setOpUserId(UserInfoHolder.getUserInfoOrEmpty().getAccount());
            opLog.setOpTime(LocalDateTime.now());
            opLog.setOpStatus(result ? OperateLogConstant.RESULT_SUCCESS : OperateLogConstant.RESULT_FAIL);
            opLog.setCreateTime(LocalDateTime.now());
            remoteSysOperateLogService.addOperateLog(opLog);
        }catch (DapException e){
            log.info(e.getMessage(),e);
        }
    }

    static Function<Class<? extends ILogService>, ILogService> getClassILogServiceFunction() {
        return clz -> {
            try {
                return clz.newInstance();
            } catch (InstantiationException | IllegalAccessException e) {
                log.error("实例化日志类异常", e);
                throw new DapThrowException("实例化日志类异常", e);
            }
        };
    }
}
*/
